<?php


namespace App\Http\Controllers\Admin\RoomManager;


use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use App\Response\Response;
use Illuminate\Http\Request;

class TypeController extends BaseController
{
    /**
     * @api {get} /room/type/all 获取所有房间类型
     *
     * @apiGroup 房间-类型
     *
     * @apiParam {Int} type 类型：0（默认）：全部；1：系统分类；2：个人分类
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": [
    {
    "id": 20,
    "room_type_name": "娱乐"
    },
    {
    "id": 26,
    "room_type_name": "电台"
    },
    {
    "id": 30,
    "room_type_name": "男生"
    },
    {
    "id": 35,
    "room_type_name": "派单"
    },
    {
    "id": 36,
    "room_type_name": "听歌"
    },
    {
    "id": 37,
    "room_type_name": "拍卖"
    },
    {
    "id": 38,
    "room_type_name": "单人房"
    },
    {
    "id": 39,
    "room_type_name": "相亲房"
    }
    ]
    }
     */
    public function all(Request $request)
    {
        $param = $request->only('type');
        $v = app('validator')->make($param, [
            'type' => 'integer|in:0,1,2',
        ]);
        if ($v->fails()) throw new BasicException(0, $v->errors()->first());

        $type = $param['type'] ?? 0;

        $where = [];
        if ($type != 0) {
            $where[] = ['type', '=', $type];
        }
        $where[] = ['is_delete', '=', 0];

        $list = app('model_room_type')->select('id', 'room_type_name')->where($where)->get();
        return Response::sendData($list);
    }
}